/**
 * 
 */
package com.zhaoyan.cms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhaoyan.cms.constant.CmsConstant;
import com.zhaoyan.cms.mapper.ArticleMapper;
import com.zhaoyan.cms.pojo.Article;
import com.zhaoyan.cms.pojo.Category;
import com.zhaoyan.cms.pojo.Channel;
import com.zhaoyan.cms.pojo.Comment;
import com.zhaoyan.cms.pojo.Vote;
import com.zhaoyan.cms.pojo.vo.ArticleVo;
import com.zhaoyan.cms.pojo.vo.VoteVo;
import com.zhaoyan.cms.service.ArticleService;

/**
 * @author zhaoyan
 *
 * 2020年1月19日
 */
@Service
public class ArticleServiceImpl implements ArticleService{
	
	
	@Autowired
	private ArticleMapper articleMapper;

	@Override
	public PageInfo<Article> hotList(Integer pageNum) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, CmsConstant.PAGE_SIZE);
		
		return new PageInfo<Article>(articleMapper.hotList());
	}

	@Override
	public List<Article> articleListByCreated(int i) {
		// TODO Auto-generated method stub
		return articleMapper.articleListByCreated(CmsConstant.ARTICLE_SIZE_CREATE);
	}

	@Override
	public List<Channel> findChannels() {
		// TODO Auto-generated method stub
		return articleMapper.findChannels();
	}

	@Override
	public PageInfo<Article> articleList(Integer categoryId, Integer channelId, Integer pageNum) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, CmsConstant.PAGE_SIZE);
		return new PageInfo<Article>(articleMapper.articleList(categoryId,channelId));
	}

	@Override
	public List<Category> findCategoryList(Integer channelId) {
		// TODO Auto-generated method stub
		return articleMapper.findCategoryList(channelId);
	}

	@Override
	public PageInfo<Article> findArticles(Integer id,Integer pageNum) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, CmsConstant.PAGE_SIZE);
		
		return new PageInfo<Article>(articleMapper.findArticles(id));
	}

	@Override
	public Integer addArticle(Article article) {
		// TODO Auto-generated method stub
		return articleMapper.addArticle(article);
	}

	@Override
	public Integer delOne(Integer id) {
		// TODO Auto-generated method stub
		return articleMapper.delOne(id);
	}

	@Override
	public Article findArticle(Integer id) {
		// TODO Auto-generated method stub
		return articleMapper.findArticle(id);
	}

	@Override
	public Integer updateOne(Article article) {
		// TODO Auto-generated method stub
		return articleMapper.updateOne(article);
	}

	@Override
	public PageInfo<Article> findArticleList(ArticleVo vo, Integer pageNum) {
		// TODO Auto-generated method stub
		
		PageHelper.startPage(pageNum, CmsConstant.PAGE_SIZE_LARGE);
		return new PageInfo<Article>(articleMapper.findArticleList(vo));
	}

	@Override
	public Integer setStatus(Integer id, Integer statusId) {
		// TODO Auto-generated method stub
		return articleMapper.setStatus(id,statusId);
	}

	@Override
	public Integer setHot(Integer id, Integer statusId) {
		// TODO Auto-generated method stub
		return articleMapper.setHot(id,statusId);
	}

	@Override
	public Integer setUser(Integer userId, Integer lockedId) {
		// TODO Auto-generated method stub
		return articleMapper.setUser(userId,lockedId);
	}

	@Override
	public PageInfo<Comment> findComment(Integer pageNum, Integer articeId) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, CmsConstant.PAGE_SIZE);
		
		return new PageInfo<Comment>(articleMapper.findComment(articeId));
	}

	@Override
	public Integer addComment(Comment comment) {
		// TODO Auto-generated method stub
		
		Integer num = articleMapper.addComment(comment);
		
		if(num > 0) {
			
			articleMapper.updateArticleCommentCount(comment.getArticleId());
		}
		
		return num;
	}

	@Override
	public Integer addVote(Vote vote) {
		// TODO Auto-generated method stub
		return articleMapper.addVote(vote);
	}
	

}
